package com.service.setting.impl;

import com.comm.R;
import com.comm.vo.DrugTableVo;
import com.controller.setting.SystemDrug;
import com.entity.DrugTable;
import com.entity.PrescriptionCost;
import com.github.pagehelper.PageHelper;
import com.mapper.setting.SystemDrugMapper;
import com.service.setting.SystemDrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDrugServiceImpl implements SystemDrugService {


    @Autowired
    private SystemDrugMapper mapper;
    @Override
    public R fundDrugs(Integer currentPage,Integer pageSize) {
        R r = new R();

        try {
            int count = mapper.count();
            com.github.pagehelper.Page<DrugTable> page = PageHelper.startPage(currentPage,pageSize);
            List<DrugTable> drugTables = mapper.fundDrugs();
            r.setCode(200);
            r.setMsg("查询成功");
            r.setCount(count);
            r.setData(drugTables);
            return r;

        }catch (Exception e){
            e.printStackTrace();
            r.setCode(200);
            r.setMsg("服务器内部错误");
            return r;
        }
    }

    @Override
    public R addDrugs(DrugTableVo drugTableVo) {

        R r = new R();
        try {
            int i = mapper.addDrugs(drugTableVo);
            r.setCode(200);
            r.setMsg("添加成功");
            return r;

        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("服务器内部错误");
            return r;
        }
    }

    @Override
    public R editDrugs(DrugTableVo drugTableVo) {
        R r = new R();
        try {
            int i = mapper.editDrugs(drugTableVo);
            r.setCode(200);
            r.setMsg("编辑成功");
            return r;

        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("服务器内部错误");
            return r;
        }
    }

    @Override
    public R delDrugs(Integer id) {
        R r = new R();
        try {
            int i = mapper.delDrugs(id);
            r.setCode(200);
            r.setMsg("删除成功");
            return r;

        }catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("服务器内部错误");
            return r;
        }
    }
}
